<?php
/**
 * 博客标签
 * @author zelome@163.com
 * $Id: index.php 10 2011-02-23 07:01:48Z sbnnest@gmail.com $
 */

require_once ('../common.inc.php');

class taglist extends Action {
	
	/**
	 * 获取博客标签列表
	 */
	function doDefault() {
		$page = $this->app->page ();
		$page->params ['template'] = 'content/taglist.tpl';
		
		$db_r = $this->app->orm ()->query ();
		$db_r->addTable ( 'tb_article_tag' );
		$db_r->addField ( 'article_tag_id' );
		$db_r->addField ( 'article_tag_count' );
		$db_r->addField ( 'article_tag_name' );
		$db_r->addField ( 'article_tag_createtime' );
		$db_r->addField ( 'article_tag_modifytime' );
		$db_r->addField ( 'article_tag_entry' );
		$rs = $db_r->getArray ();
		$page->value ( 'articleTagList', $rs );
		
		$page->output ();
	}
	
	/**
	 * 添加博客标签
	 */
	function doAdd() {
		$tagname = trim ( $_POST ['tagname'] );
		$page = $this->app->page ();
		$db_r = $this->app->orm ()->query ();
		$db_r->addTable ( 'tb_article_tag' );
		$db_r->addField ( 'article_tag_id' );
		$db_r->addField ( 'article_tag_count' );
		$db_r->addField ( 'article_tag_name' );
		$db_r->addField ( 'article_tag_createtime' );
		$db_r->addField ( 'article_tag_modifytime' );
		$db_r->addField ( 'article_tag_entry' );
		
		array (array ('id' => 1 ) );
		$db_r->insert ( array ('article_tag_name' => $tagname, 'article_tag_createtime' => date ( 'Y-m-d H:i:s' ), 'article_tag_modifytime' => date ( 'Y-m-d H:i:s' ) ) );
		
		$page = $this->app->page ();
		$page->params ['template'] = 'content/tagadd.tpl';
		$page->output ();
	}
	
	/**
	 * 跳转到添加博客标签页面
	 */
	function doAddpage() {
		$page = $this->app->page ();
		$page->params ['template'] = 'content/tagadd.tpl';
		$page->output ();
	}
	
	/**
	 * 删除博客标签
	 */
	function doDelete() {
		$article_tag_id = $_GET ['article_tag_id'];
		$db_r = $this->app->orm ()->query ();
		$db_r->addTable ( 'tb_article_tag' );
		$db_r->addField ( 'article_tag_id' );
		$db_r->addWhere ( 'article_tag_id', $article_tag_id );
		$db_r->delete ();
		
		$page = $this->app->page ();
		$page->params ['template'] = 'content/taglist.tpl';
		
		$db_r = $this->app->orm ()->query ();
		$db_r->addTable ( 'tb_article_tag' );
		$db_r->addField ( 'article_tag_id' );
		$db_r->addField ( 'article_tag_count' );
		$db_r->addField ( 'article_tag_name' );
		$db_r->addField ( 'article_tag_createtime' );
		$db_r->addField ( 'article_tag_modifytime' );
		$db_r->addField ( 'article_tag_entry' );
		$rs = $db_r->getArray ();
		$page->value ( 'articleTagList', $rs );
		
		$page->output ();
	}
	
	/**
	 * 跳转到修改博客标签页面
	 */
	function doModifypage() {
		$page = $this->app->page ();
		$page->params ['template'] = 'content/tagmodify.tpl';
		
		$article_tag_id = trim ( $_GET ['article_tag_id'] );
		$page = $this->app->page ();
		$db_r = $this->app->orm ()->query ();
		$db_r->addTable ( 'tb_article_tag' );
		$db_r->addField ( 'article_tag_id' );
		$db_r->addField ( 'article_tag_count' );
		$db_r->addField ( 'article_tag_name' );
		
		$db_r->addWhere ( 'article_tag_id', $article_tag_id );
		$result = $db_r->getRow ();
		$page->value ( 'article_tag_id', $article_tag_id );
		$page->value ( 'tb_article_tag', $article_tag_id );
		$page->value ( 'tagname', $result ['article_tag_name'] );
		$page->output ();
	}
	
	/**
	 * 修改博客标签
	 */
	function doModify() {
		$page = $this->app->page ();
		$db_r = $this->app->orm ()->query ();
		$page->params ['template'] = 'content/tagmodify.tpl';
		
		$article_tag_id = trim ( $_POST ['article_tag_id'] );
		$tagname = trim ( $_POST ['tagname'] );
		$db_r->addTable ( 'tb_article_tag' );
		$db_r->addField ( 'article_tag_id' );
		$db_r->addField ( 'article_tag_count' );
		$db_r->addField ( 'article_tag_name' );
		$db_r->addField ( 'article_tag_createtime' );
		$db_r->addField ( 'article_tag_modifytime' );
		$db_r->addField ( 'article_tag_entry' );
		
		$db_r->addWhere ( 'article_tag_id', $article_tag_id );
		$db_r->update ( array ('article_tag_name' => $tagname, 'article_tag_modifytime' => date ( 'Y-m-d H:i:s' ) ) );
		$page->output ();
	}

}

$app->run ();

?>
